﻿<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>接受人选择器</title>
    <link href="../Scripts/bootstrap/css/bootstrap.css" rel="stylesheet" />
    <link href="../Scripts/bootstrap/css/components-rounded.css" rel="stylesheet" />
    <link href="../Scripts/bootstrap/css/font-awesome.css" rel="stylesheet" />
    <link href="../Scripts/bootstrap/css/themes/default/style.min.css" rel="stylesheet" />
    <script type="text/javascript" src="../Scripts/bootstrap/js/jquery.min.js"></script>
    <script type="text/javascript" src="../Scripts/bootstrap/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="../Scripts/commonYangYH.js"></script>
    <script src="../Scripts/QueryString2016.js" type="text/javascript"></script>
    <script src="../Scripts/bootstrap/js/jquery.cokie.min.js" type="text/javascript" ></script>
    <script type="text/javascript" src="../Scripts/config.js" type="text/javascript" ></script>
    <script src="../Comm/Gener.js" type="text/javascript"></script>
    <script type="text/javascript" src="../Scripts/bootstrap/js/jstree.js"></script>
    <link href="../../DataUser/Style/ccbpm.css" rel="Stylesheet" />
    <!--
       杨玉慧.

    1. 初始化的标记是 ?DoType=Accepter_Init&FK_Node=xxxx&ToNode=0&WorkID=xxxxx.  参数: WorkID
       返回的是 节点列表 Nodes, 部门列表 Depts, 人员列表 Emps

    2, 用户选择一个节点，标记是 DoType=Accepter_Save&FK_Node=xxx&WorkID=xxx&ToNode=xxxx&SelectEmps=zhangsan,lisi.
       返回的是: 保存结果.
    -->
    <style type="text/css">
        * {
            list-style: none;
            text-align: left;
        }

        body .table tbody tr td {
            line-height: 18px;
        }

        .portlet-body,.portlet-title {
            background: #f4f9ff !important;
            border-bottom: 0px;
        }

        .customthr tr:nth-child(2n) {
            background: #d4e6fe;
        }

        .customthr tr:nth-child(2n+1) {
            background: #f4f9ff;
        }

        .customthr thead tr {
            background: #d4e6fe !important;
        }

        .btn {
            background: #2884fa !important;
            border-radius: 20px !important;
            color: white !important;
            padding: 4px 17px !important;
        }

        input[type=text], select {
            border-radius: 15px !important;
            border: #2884fa 1px solid !important;
            margin: 8px 0px !important;
            line-height: 25px;
            padding-left: 6px;
        }

        #btnSearch {
            height: 30px;
            border: none;
            border-radius: 20px;
            padding: 6px 12px;
            margin-bottom: 0;
            font-size: 14px;
            background: #2884fa !important;
            color: #fff;
        }

        #txbSearchVal {
            font-size: 14px;
        }
        /*#poptable {
                display: none;
            }*/
        #test {
        }

        .form_tree {
            background: #f4f9ff;
        }

            .form_tree #orgTxt {
                border-radius: 15px 0px 0px 15px !important;
                margin: 0px !important;
                /*border:#2884fa 1px solid;*/
            }

            .form_tree .input-group-addon {
                border-radius: 0px 15px 15px 0px !important;
                /*broder:#2884fa 1px solid;*/
            }

        #groupTable #dt ul {
            /*background: #f4f9ff;*/
            font-weight: normal;
            background: #d4e6fe;
        }

        #groupTable #dt > li {
            font-weight: bold;
        }
        #searchS {
            overflow:hidden;
        }
        #searchS div{
            height:40px;
            line-height:40px;
            text-align:left;
            float: left;
        }
    </style>
    <script type="text/javascript">
        var doType = GetQueryString("DoType");
        $(function () {
            var handler = new HttpHandler("BP.WF.HttpHandler.WF_WorkOpt");

            handler.AddPara("FK_Node", GetQueryString("FK_Node"));
            handler.AddPara("ToNode", GetQueryString("ToNode"));
            handler.AddPara("FK_Flow", GetQueryString("FK_Flow"));
            handler.AddPara("WorkID", GetQueryString("WorkID"));
            var data = handler.DoMethodReturnString("Accepter_Init");


            if (data.indexOf('info@') == 0) {
                alert(data);
                Close();
                return;
            }

            if (data.indexOf('err@') == 0) {
                alert(data);
                Close();
                return;
            }

            if (data.indexOf('url@') == 0) {

                var url = data.replace('url@', '');

                if (url.indexOf('ToNode=') > 0)
                    window.location.href = url;
                else
                    window.location.href = url + "&ToNode=" + GetQueryString("ToNode");

                return;
            }

            try {
                data = eval('(' + data + ')');
            }
            catch (err) {
                alert("转换JSON 失败" + err + data);
                return;
            }

            //获得三个数据源.
            var depts = data.Depts;
            var emps = data.Emps;

            var selected = data.Selected;

            if (emps == null || emps==undefined || emps.length == 0) {
                alert('当前节点设置的接收人范围为空,请联系管理员配置接收人范围.');
                return;
            }

            //是否是单选？
            var isSimplate = data.Selector[0].IsSimpleSelector;

            var html = "<table border=0 width='98%' > ";
            $.each(depts, function (i, dept) {

                html += "<tr><th><b> " + dept.Name + "</b></th></tr>";
                html += "<tr><td>";

                $.each(emps, function (i, emp) {

                    if (emp.FK_Dept == dept.No) {

                        //检查该人员是否被选择.
                        var isSele = false;
                        $.each(selected, function (idx, sele) {
                            if (sele.No == emp.No)
                                isSele = true;
                        });

                        //多选.
                        if (isSimplate == "0") {
                            if (isSele == true)
                                html += "&nbsp;&nbsp;<label id='lab" + emp.No + "' ><input  type='checkbox' checked=true id='" + emp.No + "'  value='" + emp.Name + "' /> <font color=green>" + emp.Name + "</font></label>";
                            else
                                html += "&nbsp;&nbsp;<label id='lab" + emp.No + "' ><input  type='checkbox'  id='" + emp.No + "'  value='" + emp.Name + "' />" + emp.Name + "</label>";
                        }

                        //单选.
                        if (isSimplate == "1") {
                            if (isSele == true)
                                html += "&nbsp;&nbsp;<label id='lab" + emp.No + "'><input name='emps'  type='radio' checked=true id='" + emp.No + "' value='" + emp.Name + "' /> <font color=green>" + emp.Name + "</font></label>";
                            else
                                html += "&nbsp;&nbsp;<label id='lab" + emp.No + "' ><input name='emps'  type='radio'  id='" + emp.No + "'  value='" + emp.Name + "' />" + emp.Name + "</label>";
                        }
                    }
                });

                html += " </td></tr>";

            });

            html += "</table>";

            $("#table").append(html);
            return;

        });

        //确定【选择接收人并发送】 / 保存.  Accepter_Save Accepter_Send
        function SendNode() {
        
            //生成选择的人员.
            var checked = $('input:checked');
            var selectedEmps = [];
            var selectedEmpLab="";
            for (var i = 0; i < checked.length; i++) {

                selectedEmps.push(checked[i].id);

                var ctrl = checked[i];

                //录制人员名称.
                selectedEmpLab += ctrl.id + "," + ctrl.value + ';';
            }

            selectedEmps = selectedEmps.join(';');
            if (selectedEmps == '' || selectedEmps == null) {
                alert('请选择人员.');
                return;
            }

//            if (window.confirm("您确定要执行发送给如下人员[ " + selectedEmpLab + " ]吗？") == false)
//                return;

            $("#Msg").html("<font color=green>正在发送请稍候...</font>");

            $.ajax({
                type: 'post',
                async: true,
                url: Handler + "?DoType=Accepter_Send&m=" + Math.random() + "&SelectEmps=" + encodeURI(selectedEmps) + "&FK_Flow=" + GetQueryString("FK_Flow") + "&WorkID=" + GetQueryString("WorkID") + "&ToNode=" + GetQueryString("ToNode"),
                dataType: 'html',
                success: function (data) {

                    if (data.indexOf('err@') == 0) {
                        alert(data);
                        return;
                    }

                    data = data.replace("'MyFlowInfo", "'../MyFlowInfo");
                    data = data.replace("'MyFlow.htm", "'../MyFlow.htm");
                    data = data.replace("'MyFlow.htm", "'../MyFlow.htm");

                    data = data.replace("'WFRpt", "'../WFRpt");
                    data = data.replace("'WFRpt", "'../WFRpt");

                    data = data.replace("'./Img", "'../Img");
                    data = data.replace("'./Img", "'../Img");
                    data = data.replace("'./Img", "'../Img");
                    data = data.replace("'./Img", "'../Img");
                    data = data.replace("'./Img", "'../Img");

                    if (data.indexOf("UnSend.htm") == -1) {
                        data = data.replace("'./WorkOpt/", "");
                        data = data.replace("'./WorkOpt/", "");
                        data = data.replace("'./WorkOpt/", "");
                    }

                    data = data.replace('@', '<br/>@');
                    data = data.replace(/@/g, '<br/>&nbsp;@');


                    if ("Accepter_Save" == doType) {
                        if (window.parent != null && window.parent.returnWorkWindowClose != null) {
                            window.parent.returnWorkWindowClose(data);
                        } else if (window.opener != undefined && window.opener.returnWorkWindowClose != undefined) {
                            window.opener.returnWorkWindowClose(data);
                        } else if (window.parent != undefined && window.parent.AccepterHtmlSave != undefined) {
                            //表单树使用
                            window.parent.AccepterHtmlSave(data);
                        } else {
                            $('body').append($('<div>' + data + '</div>'));
                            $('#btnOk').attr('disabled', true);
                        }
                        try {
                            window.opener.document.getElementById("acc_link_" + ToNode).innerHTML = "选择接受人员" + "<span style='color:black;'>(" + getSaveName + ")</span>";
                        } catch (e) {
                            //window.parent.document.getElementById("acc_link_" + ToNode).innerHTML = "选择接受人员" + "<span style='color:black;'>(" + getSaveName + ")</span>";
                        }
                        //alert('保存成功...');
                        window.close();
                        return;
                    }


                    if (window.parent != null && window.parent.returnWorkWindowClose != null) {
                        window.parent.returnWorkWindowClose(data);
                    } else if (window.opener != undefined && window.opener.returnWorkWindowClose != undefined) {
                        window.opener.returnWorkWindowClose(data);
                    } else {
                        $('body').append($('<div>' + data + '</div>'));
                        $('#btnOk').attr('disabled', true);
                    }
                }
            });
            $(".foot").hide();
        }

        //取消【选择接收人并发送】
        function Close() {

            if (window.parent != null && window.parent.returnWorkWindowClose != null) {
                window.parent.returnWorkWindowClose("取消");
                window.close();
            } else if (window.opener != undefined && window.opener.returnWorkWindowClose != undefined) {
                window.opener.returnWorkWindowClose("取消");
                window.close();
            } else {
                window.close();
            }
        }
        //初始化人员选择窗口
        function initSelectEmpModal() {
            var selectEmpModalHtml = '<div class="modal fade" id="selectEmpsModal" style="width: 80%;margin: 40px auto;">' +
               '<div class="modal-dialog" style="margin: 0px;">'
                   + '<div class="modal-content" style="border-radius:0px;width:700px;">'
                      + '<div class="modal-header">'
                          + '<button type="button" class="close" style="color:white;opacity:1;" data-dismiss="modal" aria-hidden="true">&times;</button>'
                           + '<h4 class="modal-title">选择人员</h4>'
                       + '</div>'
                       + '<div class="modal-body">'
                           + '<iframe style="width:100%;border:0px;height:400px;" id="iframeSelectEmpsForm" name="iframeSelectEmpsForm"></iframe>'
                       + '</div>'
                   + '</div><!-- /.modal-content -->'
               + '</div><!-- /.modal-dialog -->'
           + '</div>';

            $('body').append($(selectEmpModalHtml));

            $('#BtnSelectEmps').bind('click', function () {
                
                var dept = getQueryStringByNameFromUrl("?" + $.cookie('CCS'), "FK_Dept");
                if (dept == null || dept == '' || dept == undefined) {
                    dept = $.cookie('FK_Dept');
                }
                if (dept == null || dept == '' || dept == undefined) {
                    var u = new WebUser();
                    dept = u.FK_Dept;
                }
                $('#iframeSelectEmpsForm').attr('src', "SelectEmps.htm?FK_Dept=" + dept + "&FK_Node="+GetQueryString("FK_Node")+"&s=" + Math.random() + "&IsSelectMore=1");
                $('#selectEmpsModal').modal().show();
            });
        }

        //设置选中的人员
        function selectEmpsWindowClose(data) {
            $('#selectEmpsModal').modal('hide');
            if (data == '取消') {
                return;
            }
           
           $('#ToEmp').val(frames["iframeSelectEmpsForm"].window.returnVal.Name);
        }
    </script>
</head>
<body  >
      <div id="selected"></div>

    <div id="table"></div>
    
    <div style="position: fixed; bottom: 0px; right: 0px;" class="foot">
        <!--<button id="btnSaveAndClose" class="btn btn-info" onclick="SendNode('Accepter_Save')">确定</button>-->
        <button id="btnOk" class="btn btn-info" onclick="SendNode()" >发送</button>
        <button id="btnCancel" class="btn btn-info" onclick="Close()">取消</button>
    </div>
    <br />
    <center>
    <div id="Msg"></div>
    </center>

</body>
</html>
